<!--
 * @Descripttion:
 * @version:
 * @Author: 王际刚
 * @Date: 2021-11-04 09:17:19
 * @LastEditors: 王际刚
 * @LastEditTime: 2022-01-26 18:23:40
-->
<template>
  <div>
    <h1>登录页</h1>
    <div class="width250 flex">
      <el-input  v-model="input" maxlength="11" @input="oninputchange(input)" size="small" placeholder="请输入内容"></el-input>
      <el-button class="margin-left10" size="small" @click="ongetCode()"> 获取验证码 </el-button>
    </div>
    <h4>{{ code }}</h4>
  </div>
</template>

<script>
import { $ChekcUsername, $Send } from '@/api/account.js'
export default {
  name: '',
  components: {},
  props: {},
  data () {
    return {
      input: '1910605622',
      code: null
    }
  },
  computed: {},
  watch: {},
  created () {},
  methods: {
    // 验证手机号是否存在
    oninputchange (value) {
      $ChekcUsername({ username: value }).then((res) => {
        console.log(res)
        if (res.data.content.user) {
          this.$message({
            message: res.data.msg,
            type: 'error'
          })
        } else {
          this.$message({
            message: '可以注册',
            type: 'success'
          })
        }
      })
    },
    // 获取手机验证码
    ongetCode () {
      const requestData = {
        username: this.input,
        type: 'Login'// 注释
      }
      $Send(requestData).then((res) => {
        console.log(res)
        this.code = res.data.content
      }).catch((error) => {
        console.log(error)
      })
    }
  }
}
</script>

<style scoped long='less'>

</style>
